<style lang="less" scoped>
    @import './third_layer.less';
</style>
<template>
    <div ref="filterItemArea">
        <Row type="flex" align="middle">
            <Col :xs="6" :sm="6" :md="6" :lg="6"  style="padding-right: 5px">
                <Select v-model="Attribute" :transfer="true" placeholder="请选择用户属性" @change="getAttributeValue">
                    <Option v-for="item in userAttribute" :value="item.name" :key="item.name">{{item.displayName}}</Option>
                </Select>
            </Col>
            <Col :xs="4" :sm="4" :md="4" :lg="4" v-model="condition" style="margin-right: 5px">
                <Select :transfer="true" placeholder="请选择条件" style="margin-right: 5px">
                    <Option v-for="(item,index) in operatorList" :value="item.name" :key="index">{{item.displayName}}</Option>
                </Select>
            </Col>
            <Col  :xs="6" :sm="6" :md="6" :lg="6"  style="padding-right: 5px">
                <Select v-model="AttributeValue" placeholder="请选择用户属性值" :transfer="true"   >
                    <Option v-for="(item,index) in AttributeValueList" :value="item.value" :key="index">{{item.displayName}}</Option>
                </Select>
            </Col>
            <Col :xs="6" :sm="6" :md="6" :lg="6"  style="padding-right:5px;">
                <Icon @click='delSecond(subscript)' type="ios-remove-circle-outline"  size="24" class="point" />
                <Icon v-if="subscript == sublength" @click="addSecond"  type="ios-add-circle-outline" size="24" class="point"  />
            </Col>
        </Row>
    </div>
</template>
<script>

export default {
  data() {
    return {
        Attribute:'',
        condition:'',
        AttributeValueList:[],
        AttributeValue:''
    }
  },
  props:['createdConfig','userAttribute','subscript','sublength'],
  created(){
  },
  computed:{
    /**
     * 判断条件判定表
     */
    operatorList: function() {
        if(this.propertyType === 'number') {
            return [
                {
                    name: 'equal',
                    displayName: '等于',
                    valueType: 'input'
                },
                {
                    name: 'notEqual',
                    displayName: '不等于',
                    valueType: 'input'
                },
                {
                    name: 'greater',
                    displayName: '大于'
                },
                {
                    name: 'greaterOrEqual',
                    displayName: '大于等于'
                },
                {
                    name: 'less',
                    displayName: '小于'
                },
                {
                    name: 'lessOrEqual',
                    displayName: '小于等于'
                },
                {
                    name: 'isSet',
                    displayName: '有值'
                },
                {
                    name: 'isNotSet',
                    displayName: '无值'
                }
            ];
        } else if(this.propertyType === 'string') {
            return [
                {
                    name: 'equal',
                    displayName: '等于'
                },
                {
                    name: 'notEqual',
                    displayName: '不等于'
                },
                {
                    name: 'contain',
                    displayName: '包含'
                },
                {
                    name: 'notContain',
                    displayName: '不包含'
                },
                {
                    name: 'isSet',
                    displayName: '有值'
                },
                {
                    name: 'isNotSet',
                    displayName: '无值'
                }
            ];
        } else if(this.propertyType === 'boolean') {
            return [
                {
                    name: 'isTrue',
                    displayName: '为真'
                },
                {
                    name: 'isFalse',
                    displayName: '为假'
                },
                {
                        name: 'isSet',
                    displayName: '有值'
                },
                {
                    name: 'isNotSet',
                    displayName: '无值'
                }
            ];
        }
    },
    /**
     * 判断条件类型判定表
     */
    propertyType: function() {
        if(this.userAttribute[1] !=undefined ){
            if(this.userAttribute.length > 0){
                for (let i = 0; i < this.userAttribute.length; i++) {
                    if (this.userAttribute[i].name === this.Attribute) {
                        return this.userAttribute[i].type;
                    }
                }
            }
        }
        return 'number';
    },
  },
  mounted() {
	  
  },
  methods: {
        /**
         * 属性值查询方法
         */
        getAttributeValue(){
            console.log('wangck')
            // this.$axios.get(this.$api.report + "/analysis/user/property/"+this.Attribute+"/value", {
            //     headers: {
            //         "Authorization": "Bearer "+this.$sessionStore.fetch(),
            //         "Accept": "application/json"
            //     },
            //     params: {
            //         projectId: this.$store.state.projectId
            //     }
            // }).then(response => {
            //     if (response.status === 200) {
            //         this.AttributeValueList = response.data;
            //     }
            // })
            // .catch(error => {
            //     console.log(error);
            // });
            this.AttributeValueList = [
                {
                    "value": "wck",
                    "displayName": "王超克"
                }
            ]
        },
        addSecond(){
            this.$parent.addSecond();
        },
        delSecond(subindex){
            this.$parent.delSecond(subindex);
        }
    }
}

</script>

